<?php
declare (strict_types=1);

namespace addons\Pay\driver;

class Pay
{

    /**
     * @var array 支付所需参数
     */
    public $config;

    /**
     * @var string 支付标题
     */
    public $subject;

    /**
     * @var string 订单号
     */
    public $out_trade_no;

    /**
     * @var string 支付金额
     */
    public $total;

    /**
     * @var string 支付类型
     */
    public $trade_type;

    /**
     * @var string openid - 微信某些支付场景会用到
     */
    public $openid;

    /**
     * @var string 支付驱动
     */
    public $driver;

    /**
     * @var string 回调地址
     */
    public $notify_url;

    /**
     * @var string 同步跳转地址
     */
    public $redirect_url;

    /**
     * @var string 退款商户单号
     */
    public  $out_refund_no;

    /**
     * @var string 订单实付金额
     */
    public  $total_fee;

    /**
     * @var string 退款金额
     */
    public  $refund_fee;

    /**
     * @var string 微信支付驱动
     */
    protected $WeChat = "\addons\\Pay\\driver\\WeChat";

    /**
     * @var string 支付宝支付驱动
     */
    protected $AliPay = "\addons\\Pay\\driver\\AliPay";

    public function __construct()
    {
        $this->config = config('pay');
    }

    public function basic($subject, $out_trade_no, $total, $notify_url)
    {
        $this->subject = $subject;
        $this->out_trade_no = $out_trade_no;
        $this->total = $total;
        $this->notify_url = $notify_url;
        return $this;
    }

    public function create($trade_type)
    {
        $driver = $this->driver;
        return $this->$driver::create($this, $trade_type);
    }

    public function setDriver($value)
    {
        $this->driver = $value;
        return $this;
    }

    public function setSubject($value)
    {
        $this->subject = $value;
        return $this;
    }

    public function setOutTradeNo($value)
    {
        $this->out_trade_no = $value;
        return $this;
    }

    public function setTotal($value)
    {
        $this->total = $value;
        return $this;
    }

    public function setOpenId($value)
    {
        $this->openid = $value;
        return $this;
    }

    public function setNotifyUrl($value)
    {
        $this->notify_url = $value;
        return $this;
    }

    public function setReturnUrl($value)
    {
        $this->redirect_url = $value;
        return $this;
    }

    public function setTradeType($value)
    {
        $this->trade_type = $value;
        return $this;
    }

    public function basicRefund($out_trade_no, $out_refund_no, $total_fee, $refund_fee)
    {
        $this->out_trade_no = $out_trade_no;
        $this->out_refund_no = $out_refund_no;
        $this->total_fee = $total_fee;
        $this->refund_fee = $refund_fee;
        return $this;
    }

    //退款执行方法
    public function refund()
    {
        $driver = $this->driver;
        return $this->$driver::refund($this);
    }

    //退款查询执行方法
    public function queryRefund($out_refund_no)
    {
        $this->out_refund_no = $out_refund_no;
        $driver = $this->driver;
        return $this->$driver::queryRefund($this);
    }
    //退款商户单号
    public function setOutRefundNo($value)
    {
        $this->out_refund_no = $value;
        return $this;
    }

    //订单实付金额
    public function setTotalFee($value)
    {
        $this->total_fee = $value;
        return $this;
    }
    //退款金额
    public function setRefundFee($value)
    {
        $this->refund_fee = $value;
        return $this;
    }


}